package com.mingtang.online.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.webkit.WebView;
import android.widget.LinearLayout;

import com.mingtang.online.R;
import com.just.library.AgentWeb;
import com.just.library.ChromeClientCallbackManager;

public class BaseWebActivity extends BaseActivity {

    public static String INTENT_EXTRA_GOODS_ID = "INTENT_EXTRA_GOODS_ID";
    public static String INTENT_EXTRA_GOODS_URL = "INTENT_EXTRA_GOODS_URL";
    private String mGoodsUrl;
    private int mGoodsId;

    LinearLayout linear;

    public static void start(Context context, int goodsId, String goodsUrl) {
        Intent intent = new Intent(context, BaseWebActivity.class);
        intent.putExtra(INTENT_EXTRA_GOODS_ID, goodsId);
        intent.putExtra(INTENT_EXTRA_GOODS_URL, goodsUrl);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        linear = (LinearLayout) findViewById(R.id.ll_web);
        mGoodsUrl = getIntent().getStringExtra(INTENT_EXTRA_GOODS_URL);
        mGoodsId = getIntent().getIntExtra(INTENT_EXTRA_GOODS_URL, 0);
        AgentWeb mAgentWeb = AgentWeb.with(this)
                .setAgentWebParent(linear, new LinearLayout.LayoutParams(-1, -1))
                .useDefaultIndicator()
                .defaultProgressBarColor()
                .setReceivedTitleCallback(mCallback)
                .createAgentWeb()
                .ready()
                .go(mGoodsUrl);

    }

    //TODO update title
    private ChromeClientCallbackManager.ReceivedTitleCallback mCallback = new ChromeClientCallbackManager.ReceivedTitleCallback() {
        @Override
        public void onReceivedTitle(WebView view, String title) {
        }
    };
}
